package main

import (
	"github.com/gin-gonic/gin"
	"icasset/internal/dao"
	"icasset/internal/data"
	"icasset/internal/handler"
	"log"
)

func main() {
	initDB := data.InitDB()

	// 2. 初始化 DAO，并注入 data
	userDAO := dao.NewGormUserDAO(initDB)
	demandDAO := dao.NewGormDemandDAO(initDB)

	// 3. 初始化 Handler，并注入 DAO
	userHandler := handler.NewUserHandler(userDAO)
	demandHandler := handler.NewDemandHandler(demandDAO)

	//  设置 Gin 路由
	r := gin.Default()

	{
		v1 := r.Group("/user")
		v1.POST("/addUser", userHandler.CreateUser)
		v1.GET("/getAllUsers", userHandler.GetAllUsers)
		v1.POST("/login", userHandler.Login)
		v1.POST("/register", userHandler.Register)
	}

	{
		v2 := r.Group("/demand")
		v2.POST("/addDemand", demandHandler.AddDemand)
		v2.GET("/getAllDemands", demandHandler.GetAllDemands)
		v2.GET("/getDemandByPkid", demandHandler.GetDemandByPkid)
		v2.GET("/getDemandByUserId", demandHandler.GetDemandByUserId)
		v2.GET("/getDemandBySellerId", demandHandler.GetDemandBySellerId)
		//v2.GET("/queryDemandPage", demandHandler.QueryDemandPage)
		v2.POST("/confirmDemandByBuyer", demandHandler.ConfirmDemandByBuyer)
		v2.POST("/cancelDemandByBuyer", demandHandler.CancelDemandByBuyer)

	}

	// 启动服务
	log.Println("Server is running on port 8080...")
	if err := r.Run(":8080"); err != nil {
		log.Fatalf("Failed to run server: %v", err)
	}
}
